//
//  XFXReadImageDetailViewController.m
//  XFXnews
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "XFXReadImageDetailViewController.h"
#import "XFXNewsDetailModel.h"
#import "XFXReadImageView.h"
@interface XFXReadImageDetailViewController ()<XFXReadDetailImageViewDelegate,XFXReadImageViewDelegate>

@property (nonatomic, retain) NSArray *array;
@property (nonatomic, retain) NSMutableArray *allArray;
@property (nonatomic, retain) XFXNewsDetailModel *detailmodel;
@property (nonatomic, retain) XFXReadImageView *myDetailView;

@end

@implementation XFXReadImageDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.allArray = [NSMutableArray array];
    self.array = [NSMutableArray array];
    self.myDetailView = [[XFXReadImageView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.myDetailView];
    self.myDetailView.bView.myDelegate= self;
    self.myDetailView.bView.model = self.model;
    
    if (self.model.url!=0) {
        
        self.array = [[self.model.url substringFromIndex:4]componentsSeparatedByString:@"|"];
        
    }if(self.model.skipID!=0){
        
        self.array = [[self.model.skipID substringFromIndex:4]componentsSeparatedByString:@"|"];
    }
    
    NSString *url = [NSString stringWithFormat:@"http://c.3g.163.com/photo/api/set/%@/%@.json",[self.array firstObject],[self.array lastObject]];
    [XFXAFNAppTools getNewsWithHeadline:url block:^(id reulst) {
        NSLog(@"解析成功");
        NSString *title = [reulst objectForKey:@"setname"];
        NSMutableArray *array = [reulst objectForKey:@"photos"];
        for (NSDictionary *dic in array) {
            self.detailmodel = [[XFXNewsDetailModel alloc] init];
            [self.detailmodel setValuesForKeysWithDictionary:dic];
            [self.allArray addObject:self.detailmodel];
        }
        self.myDetailView.array = self.allArray;
        self.myDetailView.title = title;
        NSLog(@"%ld",self.allArray.count);
        self.myDetailView.myDelegate = self;
    } error:^(NSError *error) {
        NSLog(@"解析失败");
        
    }];
}

// 协议方法实现
- (void)push{
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
